extends ./layouts/main

block header
  script(src='../js/require.js')
  script.
    jQuery('html').addClass('navigator-page measures-page');
    window.SS = typeof window.SS === 'object' ? window.SS : {};
    _.extend(window.SS, {
      metrics: [
        {"metric":{"best_value":0.0,"delete_historical_data":false,"description":"Issues","direction":-1,"domain":"Issues","enabled":true,"hidden":false,"id":61,"name":"violations","optimized_best_value":true,"origin":"JAV","qualitative":true,"short_name":"Issues","user_managed":false,"val_type":"INT","worst_value":null}},
        {"metric":{"best_value":0.0,"delete_historical_data":true,"description":"New issues","direction":-1,"domain":"Issues","enabled":true,"hidden":false,"id":67,"name":"new_violations","optimized_best_value":true,"origin":"JAV","qualitative":true,"short_name":"New issues","user_managed":false,"val_type":"INT","worst_value":null}},
        {"metric":{"best_value":null,"delete_historical_data":false,"description":"Lines of code","direction":-1,"domain":"Size","enabled":true,"hidden":false,"id":3,"name":"ncloc","optimized_best_value":false,"origin":"JAV","qualitative":false,"short_name":"Lines of code","user_managed":false,"val_type":"INT","worst_value":null}}
      ],
      metricPeriods: {
        '1': 'since previous analysis',
        '2': 'over 365 days',
        '3': 'since previous version'
      },
      phrases: {
        'any':            'Any',
        'anytime':        'Anytime',
        'all':            'All',
        'manage':         'Manate',
        'to':             'To',
        'value':          'Value',
        'components':     'Components',
        'age':            'Age',
        'alert':          'Alert',
        'componentsOf':   'Components of',
        'date':           'Date',
        'favoritesOnly':  'Favorites only',
        'keyContains':    'Key contains',
        'lastAnalysis':   'Last analysis',
        'metric':         'Metric',
        'notSet':         'Not set',
        'nameContains':   'Name contains',
        'moreCriteria':   '+ More',
        'error':          'Error',
        'warning':        'Warning',
        'ok':             'OK',
        'days':           'days',
        'filtersList':    'Measures Filters',

        'work_duration': {
          'x_days': '{0}d',
          'x_hours': '{0}h',
          'x_minutes': '{0}min'
        }
      }
    });

block body
  div.navigator
    div.navigator-filters

  script(id='filter-bar-template' type='text/x-handlebars-template').
    <form method="get" action="../measures/search">
      <div class="navigator-filters-list"></div>
      <button class="navigator-filter-submit">Search</button>
    </form>


  script.
    requirejs.config({
      baseUrl: '../js',

      paths: {
        'backbone': 'third-party/backbone',
        'backbone.marionette': 'third-party/backbone.marionette',
        'handlebars': 'third-party/handlebars'
      },

      shim: {
        'backbone.marionette': {
          deps: ['backbone'],
          exports: 'Marionette'
        },
        'backbone': {
          exports: 'Backbone'
        },
        'handlebars': {
          exports: 'Handlebars'
        }
      }

    });

    requirejs(
        [
          'backbone', 'backbone.marionette',
          'measures/measures-filter-bar',
          'navigator/filters/base-filters',
          'navigator/filters/metric-filters'
        ],
        function (Backbone, Marionette, FilterBar, BaseFilters, MetricFilterView) {

          var NavigatorApp = new Marionette.Application();

          NavigatorApp.addRegions({
            filtersRegion: '.navigator-filters'
          });


          NavigatorApp.addInitializer(function () {
            this.filters = new BaseFilters.Filters();

            this.filters.add([
              new BaseFilters.Filter({
                name: window.SS.phrases.metric,
                property: 'metric',
                type: MetricFilterView,
                metrics: window.SS.metrics,
                periods: window.SS.metricPeriods,
                operations: { 'eq': '=', 'lt': '<', 'lte': '≤', 'gt': '>', 'gte': '≥' },
                enabled: true,
                optional: false
              })
            ]);


            this.filterBarView = new FilterBar({
              collection: this.filters,
              extra: {
                sort: '',
                asc: false
              }
            });


            this.filtersRegion.show(this.filterBarView);
          });

          NavigatorApp.start();
        });
